package com.example.yuejian.yuejian.model;

import com.example.yuejian.yuejian.base.ModleListListener;
import com.example.yuejian.yuejian.base.ModleListener;
import com.example.yuejian.yuejian.bean.ShowPhotoDetail;
import com.example.yuejian.yuejian.bean.ShowPhotoList;
import com.example.yuejian.yuejian.service.ShowPhotoService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Administrator on 2017/10/11.
 */

public class ShowPhotoModel {
    private Retrofit retrofit;

    public ShowPhotoModel() {
        retrofit = new Retrofit.Builder()
                .addConverterFactory(GsonConverterFactory.create())
                .baseUrl(Contants.BASE_URL)
                .build();
    }
    public void showPhotoList(final ModleListListener listListener)
    {
        ShowPhotoService service=retrofit.create(ShowPhotoService.class);
        Call<List<ShowPhotoList>>call=service.showPhotolist();
        call.enqueue(new Callback<List<ShowPhotoList>>() {
            @Override
            public void onResponse(Call<List<ShowPhotoList>> call, Response<List<ShowPhotoList>> response) {
                if (response.isSuccessful() && response.body() != null) {
                    listListener.onResponse(response.body());
                } else
                    listListener.onFail("onresponse fail");
            }

            @Override
            public void onFailure(Call<List<ShowPhotoList>> call, Throwable t) {
                listListener.onFail(t.toString());
            }
        });
    }
    //详情
    public void showPhotodetail(String showphotoid, final ModleListener listener)
    {
        ShowPhotoService service=retrofit.create(ShowPhotoService.class);
        Call<ShowPhotoDetail>call=service.ShowPhotoDetail(showphotoid);
        call.enqueue(new Callback<ShowPhotoDetail>() {
            @Override
            public void onResponse(Call<ShowPhotoDetail> call, Response<ShowPhotoDetail> response) {
                if (response.isSuccessful() && response.body() != null) {
                    listener.onResponse(response.body());
                } else
                    listener.onFail("onresponse fail");
            }

            @Override
            public void onFailure(Call<ShowPhotoDetail> call, Throwable t) {
                listener.onFail(t.toString());
            }
        });
    }
}
